﻿/**
 * ...
 * @author sminutoli
 */
import com.dmotiko.lib.ControlFrameMovie;
import com.dmotiko.meip.*
import com.dmotiko.general.*
import mx.transitions.easing.*;
import mx.transitions.*;

class com.dmotiko.meip.Section extends com.dmotiko.general.BaseClip
{
	private var frameControl:MovieClip;
	
	private function initClip():Void {
		frameControl = ControlFrameMovie.createControl( this );		
		
		bShowed = false;
		_alpha = 0;
		_visible = false;
		stop();
		
	}
	
	public function show():Void {
		if ( bShowed ) return;
		this._visible = true;
		frameControl.forward( { clip:this, bind: this, listener: showEnd } );
		registerTween( "fade", new Tween( this,  "_alpha", Regular.easeOut, this._alpha, 100, 0.5, true) );
	}
	
	public function hide():Void {
		if ( !bShowed ) return;
		frameControl.rewind( { clip:this, bind: this, listener: hideEnd } );
		registerTween( "fade", new Tween( this,  "_alpha", Regular.easeOut, this._alpha, 0, 0.5, true) );
	}
	
	private function showEnd():Void {
		super.showEnd();
	}
	private function hideEnd():Void {
		_visible = false;
		super.hideEnd();
	}
	
	private function tweenFinished( key:String, tween:Tween):Void {
		if ( key.indexOf("fade") > -1 && this._alpha > 0 ) {
			showEnd();
						
		} else if ( key.indexOf("fade") > -1 && this._alpha == 0 ) {
			hideEnd();
		}
	}
	
	
}